const Writable = require('stream').Writable
const writable = new Writable()

writable._write = (chunk, enc, next) => {
  console.log(`chunk is Buffer ? ${Buffer.isBuffer(chunk)}`)
  // 输出打印
  process.stdout.write(chunk.toString().toUpperCase())
  // 写入完成时，调用`next`方法通知流传入下一个数据
  process.nextTick(next)
}

// 所有数据均已写入
writable.on('finish', () => process.stdout.write('DONE'))

// 将一个数据写入流中
writable.write('a' + '\n')

writable.write('b' + '\n')

writable.write('c' + '\n')

// 没有更多数据写入时，调用end方法
writable.end()
